package com.dxy.data.webcloud.up2u.utils;

import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @CLassName: ResponseDataHolder
 * @Author: weixin
 * @Description: TODO
 * @DATE: 2018/10/8 下午4:53
 * @Version: 1.0
 */
public final class ResponseDataHolder implements Serializable {
    private static final long serialVersionUID = -1233364860788945223L;

    private boolean success;
    private String message;
    private Map<String, Object> vars;

    public ResponseDataHolder() {
    }

    private ResponseDataHolder(boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return this.message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public boolean isSuccess() {
        return this.success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public static ResponseDataHolder success() {
        ResponseDataHolder dataholder = new ResponseDataHolder(true);
        return dataholder;
    }

    public static ResponseDataHolder failure(String message) {
        ResponseDataHolder dataholder = new ResponseDataHolder(false);
        dataholder.setMessage(message);
        return dataholder;
    }

    public ResponseDataHolder set(String key, Object value) {
        if(key != null) {
            if(this.vars == null) {
                this.vars = new LinkedHashMap();
            }

            this.vars.put(key, value);
        }

        return this;
    }

    public <T> T get(String key) {
        return key != null && this.vars != null? (T) this.vars.get(key) :null;
    }
}
